package edu.iscas.appcheckclient.model.actions;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.json.JSONObject;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import edu.iscas.appcheckclient.model.Selector;

public abstract class ParamAction extends Action {

    protected JsonObject params;

    public void addParam(String property, JsonObject value){
        if(this.params == null){
            this.params = new JsonObject();
        }
        this.params.add(property, value);
    }

    public void addParam(String property, Collection<String> value){
        if(this.params == null){
            this.params = new JsonObject();
        }
        JsonArray array = new JsonArray();
        for (String item : value) {
            array.add(item);
        }
        this.params.add(property, array);
    }

    public void addParam(String property, Number value){
        if(this.params == null){
            this.params = new JsonObject();
        }
        this.params.addProperty(property, value);
    }

    public void addParam(String property, String value){
        if(this.params == null){
            this.params = new JsonObject();
        }
        this.params.addProperty(property, value);
    }

    public void addParam(String property, boolean value){
        if(this.params == null){
            this.params = new JsonObject();
        }
        this.params.addProperty(property, value);
    }

    public boolean getBoolParam(String property) {
        return this.params.get(property).getAsBoolean();
    }

    public double getDoubleParam(String property) {
        return this.params.get(property).getAsDouble();
    }

    public int getIntParam(String property) {
        return this.params.get(property).getAsInt();
    }

    public String getStringParam(String property){
        if(this.params.get(property) == null)
            return null;
        return this.params.get(property).getAsString();
    }

    public void removeParam(String property){
        this.params.remove(property);
    }

    public abstract Selector getSelector();

}
